package com.eee.machine.controller;

import com.eee.machine.common.OperateResponse;
import com.eee.machine.common.TableData;
import com.eee.machine.service.IMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/machine")
public class MachineController {

    @Autowired
    private IMachineService machineService;

    @RequestMapping("/getAllMachine")
    @ResponseBody
    TableData getAllMachine(@RequestParam(value = "page") String page,
                            @RequestParam(value = "limit") String limit){
        TableData allMachine = machineService.getAllMachine(Integer.valueOf(page), Integer.valueOf(limit));
        return allMachine;
    }


    @RequestMapping("/bindingMember")
    String bindingMember(ModelMap map, String machineId){
        map.addAttribute("machineId", machineId);
        return "machine/bindingMember";
    }


    @RequestMapping("/binding")
    @ResponseBody
    OperateResponse binding(String phone, String machineId){
        return machineService.bindingMember(phone, machineId);
    }

    @RequestMapping("/deliverGood")
    @ResponseBody
    OperateResponse deliverGood(String itemId, String machineId, Integer num, String lineSort){
        return machineService.deliverGood(machineId, lineSort, itemId, num);
    }

    @RequestMapping("/recover")
    @ResponseBody
    OperateResponse recover(@RequestParam("machineIds[]") List<String> machineIds){
        return machineService.recover(machineIds);
    }

}
